=head1 BASE INFORMATION

=head2 Filename

ApiDoc.pm

=head2 Path

/lib/Controller/WS/

=head2 Notes

=head2 ToDo's

=head2 Revision

=over 4

=item *

$HeadURL: http://catwork.googlecode.com/svn/trunk/lib/catwork/Controller/WebService/ApiDoc.pm $

=item *

$Id: ApiDoc.pm 2 2011-03-20 16:14:09Z hg.winkler.77 $

=back

=head2 Header Source Code

=cut

package catwork::Controller::WebService::ApiDoc;
use Moose;
use namespace::autoclean;

my $tool_path   = "";
my $title       = "";

BEGIN {extends 'Catalyst::Controller'; }

=head1 NAME

catwork::Controller::WS::ApiDoc - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut


=head2 index

=head3 source code

=cut

sub index :Path :Args(0) {
    my ( $self, $c ) = @_;

    $c->response->body('Matched catwork::Controller::WS::ApiDoc in WS::ApiDoc.');
}

=head2 ws_get

is called on every ws set action

=head3 source code

=cut

sub ws_get :Chained('/') :PathPart('ws/apidoc/get') :CaptureArgs(0) {

    my ($self, $c) = @_;

    $tool_path = "catwOrk -> ApiDoc -> Viewer";
    $title = "API Doc Browser";

}

=head2 ws_set

is called on every ws set action

=head3 source code

=cut

sub ws_set :Chained('/') :PathPart('ws/apidoc/set') :CaptureArgs(0) {

    my ($self, $c) = @_;

}

=head2 doc

is used to got a single html doc for one perl file and is the main part in the
chain for /ws/apidoc/get/doc/*

To test it try http://server/ws/apidoc/get/doc/json?path=catwork%2Flib%2Fcatwork.pm&name=catwork.pm

=head3 url

/ws/apidoc/generate/* only supported is "json"!

=head3 parameter

    path => "catwork/catwork.pm"
    name => "catwork.pm"

=head3 stash

    $c->stash(
        html               => $result->{html},
        warnings           => $result->{warnings},
        header_subtitle    => $tool_path." -> ".$filename,
        footer             => "/apidoc/root/".$path,
    );

=head3 source code

=cut

sub doc :Chained('ws_get') :PathPart('doc') :Args(1) {

    my ($self, $c, $view) = @_;

    my $path = $c->request->{parameters}->{path};
    my $filename = $c->request->{parameters}->{name};
    my $result = $c->model('APIDoc')->pod2html($c, $path);

    $c->stash(
        html               => $result->{html},
        warnings           => $result->{warnings},
        header_subtitle    => $tool_path." -> ".$filename,
        footer             => "/apidoc/root/".$path,
    );

    $c->forward("/set_view/$view");


}

=head2 search

performed a search over all perl files in the apidoc and is the main part in the
chain for /ws/apidoc/get/search/*

To test it try http://server/ws/apidoc/get/search/json?search=test

=head3 url

/ws/apidoc/get/search/* only supported is "json"!

=head3 parameter

    search => "search string"

=head3 stash

    $c->stash(
        result               => $result,
        warnings           => "",
        header_subtitle    => $tool_path." -> Search -> Result -> ".$search,
        footer             => "/apidoc/search/result/$search",
    );

=head3 source code

=cut

sub search :Chained('ws_get') :PathPart('search') :Args(1) {

    my ($self, $c, $view) = @_;

    my $search = $c->request->{parameters}->{search};
    my $result = $c->model('APIDoc')->search($c, $search);

    $c->stash(
        result               => $result,
        warnings           => "",
        header_subtitle    => $tool_path." -> Search -> Result -> ".$search,
        footer             => "/apidoc/search/result/$search",
    );

    $c->forward("/set_view/$view");

}

=head2 project_report

performed a report generation based on the script /script/catwork_cloc.pl and
is the main part in the chain for /ws/apidoc/get/project_report/*

To test it try http://server/ws/apidoc/get/project_report/json?search=test

=head3 url

/ws/apidoc/get/project_report/* only supported is "json"!

=head3 parameter

=head3 stash

    $c->stash(
        result             => $project_report,
        warnings           => "",
        header_subtitle    => $tool_path." -> Project Report",
        footer             => "/apidoc/project_report/",
    );

=head3 source code

=cut

sub project_report :Chained('ws_get') :PathPart('project_report') :Args(1) {

    my ($self, $c, $view) = @_;

    my $project_report = $c->model('APIDoc')->get_project_report($c);

    $c->stash(
        result             => $project_report,
        warnings           => "",
        header_subtitle    => $tool_path." -> Project Report",
        footer             => "/apidoc/project_report/",
    );

    $c->forward("/set_view/$view");

}

=head2 summary

return a list of all Docs (with description etc.) in the given path.

To test it try http://server/ws/apidoc/get/project_report/json?path=catwork%2Flib%2Fcatwork%2FView%2F

=head3 url

/ws/apidoc/get/summary/* only supported is "json"!

=head3 parameter

    path => "catwork/catwork/View/"

=head3 stash

    $c->stash(
        result             => $summary,
        warnings           => "",
        header_subtitle    => $tool_path." -> Summary -> ".$path,
        footer             => "/apidoc/summary/".$path,
    );

=head3 source code

=cut

sub summary :Chained('ws_get') :PathPart('summary') :Args(1) {

    my ($self, $c, $view) = @_;
    my $path = $c->request->{parameters}->{path};
    my $summary = $c->model('APIDoc')->get_summary($c, $path);

    $c->stash(
        result             => $summary,
        warnings           => "",
        header_subtitle    => $tool_path." -> Summary -> ".$path,
        footer             => "/apidoc/summary/".$path,
    );

    $c->forward("/set_view/$view");

}

=head2 single_search_result

is used to got a single doc for one file with marked search results

http://server/ws/apidoc/get/single_search_result/json?path=catwork%2Flib%2Fdoc%2FStyleGuide.pm&search=test

=head3 url

/ws/apidoc/get/single_search_result/* only supported is "json"!

=head3 parameter

    search  => "search string"
    path    => "catwork/doc/StyleGuide.pm"

=head3 stash

    $c->stash(
        result             => $result,
        warnings           => "",
        header_subtitle    => $tool_path." -> Search -> Result -> ".$search,
        footer             => "/apidoc/search/result/$search",
    );

=head3 source code

=cut

sub single_search_result :Chained('ws_get') :PathPart('single_search_result') :Args(1) {

    my ($self, $c, $view) = @_;

    my $search = $c->request->{parameters}->{search};
    my $path = $c->request->{parameters}->{path};
    my $result = $c->model('APIDoc')->single_search_result($c, $path, $search);

    $c->stash(
        result             => $result,
        warnings           => "",
        header_subtitle    => $tool_path." -> Search -> Result -> ".$search,
        footer             => "/apidoc/search/result/$search",
    );

    $c->forward("/set_view/$view");

}

=head1 AUTHOR

Hans-Georg Winkler,,,

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

__PACKAGE__->meta->make_immutable;

